package com.code.app.core;

import android.os.Handler;
import android.util.Log;
import android.webkit.JavascriptInterface;

import com.code.app.annotation.Tip;

public class JavaScriptInterfaceImpl implements IJavaScriptInterface {

    private final String TAG = "JavaScriptInterface";

    private IJavaScriptInterface javaScriptInterface ;

    private Handler handler;

    public android.os.Handler getHandler() {
        return handler;
    }

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    public IJavaScriptInterface getJavaScriptInterface() {
        return javaScriptInterface;
    }

    public void setJavaScriptInterface(IJavaScriptInterface javaScriptInterface) {
        this.javaScriptInterface = javaScriptInterface;
    }

    @Tip(msg = "通过JavaScript调用Java方法不是在UI线程中执行")
    @JavascriptInterface
    @Override
    public void setValue(final String msg) {
        Log.i(TAG, msg);
        handler.post(new Runnable() {
            @Override
            public void run() {
                javaScriptInterface.setValue(msg);
            }
        }) ;
    }
}
